//
//  ContentsCell.m
//  AnimationRecommend
//
//  Created by ljm on 2017/2/18.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "ContentsCell.h"

@implementation ContentsCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //漫语
        _detailTitleLabel = [[UILabel alloc]initWithFrame:AAdaptionRect(0, 0, 200, 45)];
        _detailTitleLabel.center = CGPointMake(kwidth/2, 20);
        _detailTitleLabel.text = @"- 漫语 -";
        _detailTitleLabel.textAlignment = NSTextAlignmentCenter;
        _detailTitleLabel.font = [UIFont fontWithName:ManYu_FontStr size:45*AAdaptionWidth()];
        [self.contentView addSubview:_detailTitleLabel];
        
        
        NSString *name = @"《东京食尸鬼》/《东京喰种》是由石田スイ所创作的漫画作品，TV动画于2014年7月3日在TOKYO MX电视台播出。 石田スイ创作，在集英社《周刊Young Jump》连载中的漫画《东京食尸鬼》（东京喰种）";//于2014年1月宣布“动画化决定”，详细在后出版的《周刊Young Jump》杂志上发表。 以架空世界的现代东京为背景，描述以人肉为主食，被称为喰种（Ghoul）之人型怪物。分类上被归类为“黑暗奇幻”（Dark fantasy），同时也含有科学奇幻的要素";
        
        /*
         *    根据文字的数量加载所需高度
         */
        CGSize highImage = [name boundingRectWithSize:CGSizeMake((kBaseWidth - 30*2)*AAdaptionWidth(), MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin  attributes:@{NSFontAttributeName:[UIFont fontWithName:ManYu_FontStr size:30*AAdaptionWidth()]} context:nil].size;
//        NSLog(@"这个highImage是%f",highImage.height/AAdaptionWidth());
        
        //中心内容
        _contentLabel = [[UILabel alloc]initWithFrame:AAdaptionRect(30, CGRectGetMaxY(self.detailTitleLabel.frame)/AAdaptionWidth() + 30, kBaseWidth - 30*2, highImage.height/AAdaptionWidth())];
        _contentLabel.font = [UIFont fontWithName:ManYu_FontStr size:30*AAdaptionWidth()];
        _contentLabel.numberOfLines = 0;
        _contentLabel.textAlignment = NSTextAlignmentLeft;
        _contentLabel.textColor = [UIColor cz_colorWithRed:0 green:0 blue:0];
        _contentLabel.alpha = 0.8;
        [self.contentView addSubview:_contentLabel];
        
        //出处
        _detailSourceLabel = [[UILabel alloc]initWithFrame:AAdaptionRect(0, 0, (kwidth - 100)/AAdaptionWidth(), 40)];
        _detailSourceLabel.center = CGPointMake(kwidth/2, CGRectGetMaxY(self.contentLabel.frame) + AAdaption(30));
//        _detailSourceLabel.text = @"斯坦尼斯拉夫斯基";
        _detailSourceLabel.textAlignment = NSTextAlignmentRight;
        _detailSourceLabel.font = [UIFont fontWithName:ManYu_FontStr size:28*AAdaptionWidth()];
        [self.contentView addSubview:_detailSourceLabel];
    }
    return self;
}

+(instancetype)loadCellWithTableView:(UITableView *)tableView {
    
    static NSString *cellIdentifier = @"ContentsCell";
    
    ContentsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (!cell) {
        cell = [[ContentsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
